//
//  OrderViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-5-20.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "OrderViewController.h"
#import "OrderManagementTableViewCell.h"
#import "GuideListTableViewCell.h"
//#import "ChengSeTableViewCell.h"
#import "OldMeterialTableViewCell.h"
#import "HZAreaPickerView.h"
#import <CoreLocation/CoreLocation.h>
#import "OrderDetailTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "EGORefreshTableHeaderView.h"
#import "SearchMemberTableViewCell.h"
#import "FPNumberPadView.h"
#import "APLPrintPageRenderer.h"
#import "CashierViewController.h"
#import "OrderDetailViewController.h"
#import "CancelOrderOrDepositViewController.h"
#import "DepositDetailViewController.h"
#import "FilterViewController.h"
#import "CommonProductDetailViewController.h"
#import "AddMemberViewController.h"
@interface OrderViewController ()<OrderManagementTableViewCelllDelegate,HZAreaPickerDelegate,EGORefreshTableHeaderDelegate,FPNumberPadViewDelegate,CashierViewControllerDelegate,OrderDetailDelegate,CancelOrderOrDepositDelegate,DepositDetailDelegate,FilterViewControllerDelegate,AddMemberDelegate,CommonProductDetailDelegate>
{
    AddMemberViewController *addMemberVC;
    FilterViewController *filterVC;
    EGORefreshTableHeaderView *_refreshHeaderView;
    BOOL _reloading;
    
    OrderDetailViewController *orderDetailVC;
    CancelOrderOrDepositViewController *cancelOrderVC;
    CashierViewController *cashierVC;
    DepositDetailViewController *depositDetailVC;
    CommonProductDetailViewController *commonProductDetailVC;
    
    NSUInteger _memberPageIndex;
    NSUInteger _memberTotalCount;
    NSUInteger _memberTotalPage;
    
    NSMutableArray *memberCodeArray;
    NSMutableArray *memberNameArray;
    NSMutableArray *memberPhoneArray;
    NSMutableArray *memberGradeArray;
    NSMutableArray *memberAddressArray;
    NSMutableArray *memberIntegralArray;
    NSMutableArray *memberIntegralAmountArray;
    NSMutableArray *memberSexArray;

    NSUInteger _PageIndex;
    NSUInteger _TotalCount;
    NSUInteger _TotalPage;
   // NSUInteger _totalOrder;
    
    NSMutableArray *orderNumArray;
    NSMutableArray *orderDocTypeArray;
    NSMutableArray *orderTotalNumberArray;
    NSMutableArray *orderStatusArray;
    NSMutableArray *orderStatus1Array;
    NSMutableArray *orderWeightArray;
    NSMutableArray *orderShipmentStatusArray;
    NSMutableArray *productNameArray;
    NSMutableArray *guideNameArray;
    NSMutableArray *memberNameListArray;
    NSMutableArray *priceArray;
    NSMutableArray *dateArray;
    
    NSString *guideCodeStr;
    NSString *memberCodeStr;
    BOOL isOpened;
    
    NSUInteger orderListCellTag;
    
    
    NSMutableArray *orderDetailProductNameArray;
    NSMutableArray *orderDetailProductCodeArray;
    NSMutableArray *orderDetailProductPriceArray;
    NSMutableArray *orderDetailProductUrlArray;
    NSMutableArray *orderDetailWeightArray;
    NSMutableArray *orderDetailProductAddressArray;
    NSMutableArray *orderDetailAttributeArray;
    
    NSString *orderStr;
    
    NSString *buShouYinOrBuDengStr;
    
    NSInteger cellTag;
    
    float depositPrice;
    
    UITextField *inputTextField;
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSMutableArray *selectFilterCodeArray;
    NSMutableArray *selectFilterNameArray;
    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    NSString *startTimeStr;
    NSString *endTimeStr;

    NSString *integralAvailabalStr;
    

}
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@property (strong, nonatomic) NSString *areaValue, *cityValue;
@property (strong, nonatomic) HZAreaPickerView *locatePicker;

@end

@implementation OrderViewController
@synthesize areaValue=_areaValue, cityValue=_cityValue;
@synthesize locatePicker=_locatePicker;
-(void)viewWillAppear:(BOOL)animated
{
   // NSLog(@"self===%@",self);
     if ([_isLoad isEqualToString:@"N"]) {
    if (orderDetailVC.view!=nil) {
        
        [orderDetailVC removeFromParentViewController];
        [orderDetailVC.view removeFromSuperview];
        
    }
   if (addMemberVC.view!=nil) {
             if (addMemberVC.timer!=nil) {
                 [addMemberVC.timer invalidate];
                 addMemberVC.timer=nil;
             }
             
             [addMemberVC removeFromParentViewController];
             [addMemberVC.view removeFromSuperview];
             
        }

    if (commonProductDetailVC.view!=nil) {
        
        [commonProductDetailVC removeFromParentViewController];
        [commonProductDetailVC.view removeFromSuperview];
        
    }

    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }

    if (cashierVC.view!=nil) {
        
        [cashierVC removeFromParentViewController];
        [cashierVC.view removeFromSuperview];
        
    }
    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }

    [self initOrderList];
  
    [self initOrderDetailView];
    [self initSearMemberView];
    [self initOrderFilterView];
    
    
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];
     }
}
-(void)initOrderFilterView
{
    inputFilterCodeArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
    selectFilterNameArray=[NSMutableArray array];
    selectCustomTimeArray=[NSMutableArray array];
    
    startTimeStr=@"";
    endTimeStr=@"";
    
    [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
    [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    // [_orderFilterViewContainer bringSubviewToFront:_resetFilterBtn];
    
    _orderFilterBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _orderFilterBtn.layer.borderWidth= 1.0f;
    _orderFilterBtn.layer.cornerRadius=4;
    
    [_orderFilterBtn addTarget:self action:@selector(orderFilterBtnClick) forControlEvents:UIControlEventTouchUpInside];

}
-(void)initSearMemberView
{
    memberCodeArray=[NSMutableArray array];
    memberNameArray=[NSMutableArray array];
    memberPhoneArray=[NSMutableArray array];
    memberGradeArray=[NSMutableArray array];
    memberAddressArray=[NSMutableArray array];
    memberIntegralArray=[NSMutableArray array];
    memberSexArray=[NSMutableArray array];
    memberIntegralAmountArray=[NSMutableArray array];
    
    [_searchMemberAlphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_searchMemberAlphaView addTarget:self action:@selector(searchMemberAlphaViewClick) forControlEvents:UIControlEventTouchUpInside];
    
    CGRect frame1=_searchMemberViewContainer.frame;
    frame1.origin.y=768;
    [_searchMemberViewContainer setFrame:frame1];
}
-(void)searchMemberAlphaViewClick
{
    [_searchMemberTextField resignFirstResponder];
    
    [_searchTextField resignFirstResponder];
    CGRect frame1=_searchMemberViewContainer.frame;
    frame1.origin.y=768;
    [_searchMemberViewContainer setFrame:frame1];
    
}
-(void)orderFilterBtnClick
{
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    filterVC=[[FilterViewController alloc] init];
    filterVC.delegate=self;
    filterVC.docTypeStr=@"Order";
    filterVC.selectCustomTimeArray=[NSMutableArray arrayWithArray:selectCustomTimeArray];
    filterVC.startTimeStr=startTimeStr;
    filterVC.endTimeStr=endTimeStr;
    // NSLog(@"selectFilterNameArray=22222======%@",selectFilterNameArray);
    filterVC.selectFilterNameArray=[NSMutableArray arrayWithArray:selectFilterNameArray];
    filterVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:filterVC];
    [self.view addSubview:filterVC.view];
}
-(void)confirmFilterBtnClick:(NSMutableArray *)commonFilterTypeCodeArray commonSelectFilterCodeArray:(NSMutableArray *)commonSelectFilterCodeArray commonInputFilterCodeArray:(NSMutableArray *)commonInputFilterCodeArray commonInputMinResultFilterNameArray:(NSMutableArray *)commonInputMinResultFilterNameArray commonInputMaxResultFilterNameArray:(NSMutableArray *)commonInputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:(NSMutableArray *)commonCustomTimeFilterTypeCodeArray commonSelectCustomTimeArray:(NSMutableArray *)commonSelectCustomTimeArray commonSelectFilterNameArray:(NSMutableArray *)commonSelectFilterNameArray  commonStartTimeStr:(NSString *)commonStartTimeStr commonEndTimeStr:(NSString *)commonEndTimeStr isDefault:(NSString *)isDefault
{
    
    if ([isDefault isEqualToString:@"Y"]) {
        //  NSLog(@"_isDefault0000===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    }
    else{
        // NSLog(@"_isDefault1111===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:203.0f/255.0f green:164.0f/255.0f blue:67.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"yishaixuan_.png"]];
    }
    
    filterTypeCodeArray=commonFilterTypeCodeArray;
    selectFilterCodeArray=commonSelectFilterCodeArray;
    inputFilterCodeArray=commonInputFilterCodeArray;
    inputMinResultFilterNameArray=commonInputMinResultFilterNameArray;
    inputMaxResultFilterNameArray=commonInputMaxResultFilterNameArray;
    customTimeFilterTypeCodeArray=commonCustomTimeFilterTypeCodeArray;
    selectCustomTimeArray=commonSelectCustomTimeArray;
    selectFilterNameArray=commonSelectFilterNameArray;
    
    startTimeStr=commonStartTimeStr;
    endTimeStr=commonEndTimeStr;
    
    [orderNumArray removeAllObjects];
    [orderTotalNumberArray removeAllObjects];
    [orderStatusArray removeAllObjects];
    [orderDocTypeArray removeAllObjects];
    [orderWeightArray removeAllObjects];
    [orderShipmentStatusArray removeAllObjects];
    [productNameArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [memberNameListArray removeAllObjects];
    [priceArray removeAllObjects];
    [dateArray removeAllObjects];
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];

    
}

-(void) loadOrderNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _TotalCount<=orderNumArray.count)
        return;
    if(oldPageNum == 0){
        [orderNumArray removeAllObjects];
        [_orderListTabelView reloadData];
    }
    _PageIndex=oldPageNum+1;
    [self requestOrderList: _PageIndex pageSize:7];
}
-(void)requestOrderList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:_searchTextField.text forKey:@"KeyWord"];
        
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<filterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            [dic setValue:[filterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            [dic setValue:[selectFilterCodeArray objectAtIndex:i] forKey:@"FilterCode"];
            [mDocumentLine addObject:dic];
            
        }
        NSMutableArray *mDocumentLine1=[NSMutableArray array];
        for (int i=0; i<customTimeFilterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            [dic setValue:[customTimeFilterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            [dic setValue:startTimeStr forKey:@"Value1"];
            [dic setValue:endTimeStr forKey:@"Value2"];
            [mDocumentLine1 addObject:dic];
            
        }
        
        [params setObject:mDocumentLine forKey:@"DataLineFileterParam"];
        [params setObject:mDocumentLine1 forKey:@"DataLineFileterParam2"];
      //  NSLog(@"paramsLIST11111====%@",params);
        [HttpRequest requestData:@"Guide/OrderList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    //    NSLog(@"333==%@",severDataDict.dataDict);
                    _TotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    NSInteger numberInteger=[[severDataDict.dataDict objectForKey:@"DocQCount"] integerValue];
                    float gramInteger=[[severDataDict.dataDict objectForKey:@"DocGramTotal"] floatValue];
                    float priceInteger=[[severDataDict.dataDict objectForKey:@"DocPriceTotal"] floatValue];
                    _totalOrderLabel.text=[NSString stringWithFormat:@"共有%lu个订单  %ld件/%@g   ¥%@",(unsigned long)_TotalCount,(long)numberInteger,[Global floatConvertPercentile:gramInteger],[Global floatConvertPercentile:priceInteger]];
                    if (_TotalCount%7!=0) {
                        _TotalPage=_TotalCount/7+1;
                    }
                    else if (_TotalCount%7==0)
                    {
                        _TotalPage=_TotalCount/7;
                    }
                    
                    
                    NSMutableArray *mOrderArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    
                    //     NSLog(@"mOrderArray===%@",mOrderArray);
                    if ( mOrderArray.count>0) {
                        for (int i=0; i< mOrderArray.count; i++) {
                            
                            [orderNumArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"DocNum"]];
                            [orderTotalNumberArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"Number"]];
                            [orderStatusArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                            [orderDocTypeArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"DocType"]];
                            [orderWeightArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"GramTotal"]];
                            [orderShipmentStatusArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"ShipmentStatus"]];
                            [productNameArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"ItemName"]];
                            [guideNameArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"GuideName"]];
                            [memberNameListArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"MemberName"]];
                            [priceArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"DocTotal"]];
                            [dateArray addObject:[[mOrderArray objectAtIndex:i] objectForKey:@"DocDate"]];
                        }
                    }
                    [_orderListTabelView reloadData];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                        [Global loginViewController:self noteStr:requestResultStr];
                        // [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}


-(void) loadMemberNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _memberTotalCount<=memberCodeArray.count)
        return;
    if(oldPageNum == 0){
        [memberCodeArray removeAllObjects];
        [_searchMemberTableView reloadData];
    }
    _memberPageIndex=oldPageNum+1;
    [self requestMemberList: _memberPageIndex pageSize:8];
}
-(void)requestMemberList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        //        NSString *pageSizeStr=[NSString stringWithFormat:@"%d",pageSize];
        //        NSString *pageIndexStr=[NSString stringWithFormat:@"%d",pageIndex];
        
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:_searchMemberTextField.text forKey:@"KeyWord"];
        //   NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"Guide/MemberList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    //  NSLog(@"tttt11====%@",severDataDict.dataDict);
                    _memberTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _totalMemberLabel.text=[NSString stringWithFormat:@"共有%lu个结果",(unsigned long)_memberTotalCount];
                    if (_memberTotalCount%8!=0) {
                        _memberTotalPage=_memberTotalCount/8+1;
                    }
                    else if (_memberTotalCount%8==0)
                    {
                        _memberTotalPage=_memberTotalCount/8;
                    }
                    NSMutableArray *mMembersArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"DataLine"]];
                    // NSLog(@"mMembersArray===%@",mMembersArray);
                    if ( mMembersArray.count>0) {
                        for (int i=0; i< mMembersArray.count; i++) {
                            
                            [memberCodeArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"UserCode"]];
                            [memberNameArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"UserName"]];
                            [memberAddressArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"Address"]];
                            [memberPhoneArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"Phone"]];
                            [memberGradeArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"Grade"]];
                            [memberIntegralArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"Integral"]];
                            [memberIntegralAmountArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"IntegralAmount"]];
                            [memberSexArray addObject:[[mMembersArray objectAtIndex:i] objectForKey:@"Sex"]];
                        }
                    }
                    
                    [_searchMemberTableView reloadData];
                    
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
//                    if (timer!=nil) {
//                        [timer invalidate];
//                        timer=nil;
//                    }
//                    UIViewController *controller=[[GlobalViewController alloc]init];
//                    [self.navigationController pushViewController:controller animated:YES];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                         [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}

-(void)initOrderDetailView
{
    orderDetailProductNameArray=[NSMutableArray array];
    orderDetailProductPriceArray=[NSMutableArray array];
    orderDetailProductUrlArray=[NSMutableArray array];
    orderDetailWeightArray=[NSMutableArray array];
   orderDetailProductAddressArray=[NSMutableArray array];
    orderDetailAttributeArray=[NSMutableArray array];
    orderDetailProductCodeArray=[NSMutableArray array];
    
  

}
-(void)initOrderList
{
    _searchTextField.text=@"";
    orderNumArray=[NSMutableArray array];
    orderTotalNumberArray=[NSMutableArray array];
    orderStatusArray=[NSMutableArray array];
    orderStatus1Array=[NSMutableArray array];
    orderDocTypeArray=[NSMutableArray array];
    orderWeightArray=[NSMutableArray array];
    orderShipmentStatusArray=[NSMutableArray array];
    productNameArray=[NSMutableArray array];
    guideNameArray=[NSMutableArray array];
    memberNameListArray=[NSMutableArray array];
    priceArray=[NSMutableArray array];
    dateArray=[NSMutableArray array];
    
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
     if (alertView.tag==200000)
    {
        if (buttonIndex == 0)
        {
            if ([Global getLoginToken].length>0) {
                [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
                NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
                [params setObject:[Global getLoginToken] forKey:@"Token"];
                [params setObject:[orderNumArray objectAtIndex:orderListCellTag] forKey:@"DocNum"];
                [params setObject:@"Order" forKey:@"DocType"];
                
                [HttpRequest requestData:@"Guide/CancelDocument" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
                    // NSLog(@"serrr111==%@",severDataDict.dataDict);
                    // [_cashierSearchMemberTextField resignFirstResponder];
                    if (isSuccess) {
                        if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                            [Global hideProgressHUDInternal:self.view];
                            NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                            //  [Global showTextHud:requestResultStr view:self.view];
                            [Global showTextHudSub:requestResultStr view:self.view];
                            NSIndexPath *indexPath1= [NSIndexPath indexPathForRow:orderListCellTag inSection:0];
                            UITableViewCell *cell = [_orderListTabelView cellForRowAtIndexPath:indexPath1];
                            OrderManagementTableViewCell *orderListCell=( OrderManagementTableViewCell *)cell;
                            orderListCell.orderStatusLabel.text=@"【已取消】";
                            [orderDocTypeArray replaceObjectAtIndex:orderListCellTag withObject:@"L"];
                            [orderStatusArray replaceObjectAtIndex:orderListCellTag withObject:@"已取消"];
                            [orderListCell.orderStatusLabel setTextColor:[Global parseStatusColor:@"已取消"]];
                            orderListCell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                            
                            [orderListCell.buShouYinButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                            //[cell.confirmArrivalBtn setTintColor:];
                            [orderListCell.buShouYinButton setUserInteractionEnabled:NO];
                            
                            orderListCell.huiYuanBuDengButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                            
                            [orderListCell.huiYuanBuDengButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                            
                            //[cell.confirmArrivalBtn setTintColor:];
                            [orderListCell.huiYuanBuDengButton setUserInteractionEnabled:NO];
                            
                        }
                        else
                        {
                            [Global hideProgressHUDInternal:self.view];
                            NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                            //  [Global showTextHud:requestResultStr view:self.view];
                            [Global showTextHudSub:requestResultStr view:self.view];
                            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                                if (_timer!=nil) {
                                    [_timer invalidate];
                                    _timer=nil;
                                }
                                [Global loginViewController:self noteStr:requestResultStr];
                                //  [Global loginViewController:self];
                            }
                            
                        }
                    }
                    else
                    {
                        [Global hideProgressHUDInternal:self.view];
                        [Global showTextHudSub:@"连接失败" view:self.view];
                    }
                }];
            }

        }
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    if (_refreshHeaderView == nil) {
        EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _orderListTabelView.bounds.size.height, self.view.frame.size.width, _orderListTabelView.bounds.size.height)];
        view.delegate = self;
        [_orderListTabelView addSubview:view];
        _refreshHeaderView = view;
        
        
    }
    
    //  update the last update date
    [_refreshHeaderView refreshLastUpdatedDate];
    // Do any additional setup after loading the view from its nib.
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    [orderNumArray removeAllObjects];
    [orderTotalNumberArray removeAllObjects];
    [orderStatusArray removeAllObjects];
    [orderDocTypeArray removeAllObjects];
    [orderWeightArray removeAllObjects];
    [orderShipmentStatusArray removeAllObjects];
    [productNameArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [memberNameListArray removeAllObjects];
    [priceArray removeAllObjects];
    [dateArray removeAllObjects];
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    
}

- (void)doneLoadingTableViewData{
    
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_orderListTabelView];
    
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView==_orderListTabelView) {
 
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (scrollView==_orderListTabelView) {
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    }
    
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return _reloading; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView==_searchMemberTableView) {
        return memberCodeArray.count;
    }

   else if (tableView==_orderListTabelView) {
        return orderNumArray.count;
    }
    
    return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_orderListTabelView) {
        return 120;
    }
    else if (tableView==_searchMemberTableView)
        return 90;
    else
        return 50;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_orderListTabelView) {
           static NSString * const  OrderManagementIdentifier = @"OrderManagementIdentifier";
        OrderManagementTableViewCell *cell=( OrderManagementTableViewCell *)[tableView dequeueReusableCellWithIdentifier: OrderManagementIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"OrderManagementTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
            cell.delegate=self;
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        cell.piaoJuBuDaButton.tag=indexPath.row;
        cell.buShouYinButton.tag=indexPath.row;
        cell.huiYuanBuDengButton.tag=indexPath.row;
        if (orderDocTypeArray.count>0) {
            if ([[orderDocTypeArray objectAtIndex:indexPath.row]isEqualToString:@"P"]) {
            cell.orderDocTypeLabel.text=@"预";
                cell.orderStatus1Label.hidden=NO;
            }
            else
            {
                cell.orderStatus1Label.hidden=YES;
                cell.orderDocTypeLabel.text=@"";
            }
            
           // [self resizeLabel:cell.orderDocTypeLabel];
            [Global resizeForLable:cell.orderDocTypeLabel WithText:cell.orderDocTypeLabel.text parentView:self.view];
            CGRect frame=cell.orderNumLabel.frame;
            frame.origin.x=cell.orderDocTypeLabel.frame.origin.x+cell.orderDocTypeLabel.frame.size.width+2;
            cell.orderNumLabel.frame=frame;

            // }
            
        }

              if (orderNumArray.count>0) {
            cell.orderNumLabel.text=[orderNumArray objectAtIndex:indexPath.row];
            [Global resizeForLable:cell.orderNumLabel WithText:cell.orderNumLabel.text parentView:self.view];
           // [self resizeLabel:cell.orderNumLabel];
            CGRect frame=cell.orderStatusLabel.frame;
            frame.origin.x=cell.orderNumLabel.frame.origin.x+cell.orderNumLabel.frame.size.width-5;
            cell.orderStatusLabel.frame=frame;
        }

        //  NSLog(@"memberContacts11111==%@",memberContacts);
        if (guideNameArray.count>0) {
            cell.guideNameLabel.text=[guideNameArray objectAtIndex:indexPath.row];
            //[self resizeLabel:cell.guideNameLabel];
             [Global resizeForLable:cell.guideNameLabel WithText:cell.guideNameLabel.text parentView:self.view];
            CGRect frame=cell.memberNameTagLabel.frame;
            frame.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+12;
            cell.memberNameTagLabel.frame=frame;
            
          

        }
       NSString *memberNameStr=@"";
        if (memberNameListArray.count>0) {
            memberNameStr=[NSString stringWithFormat:@"%@",[memberNameListArray objectAtIndex:indexPath.row]];
            if (memberNameStr.length>0) {
                cell.memberNameLabel.text=memberNameStr;
               // [cell.huiYuanBuDengButton setTitle:@"会员变更" forState:UIControlStateNormal];
            }
            else
            {
                cell.memberNameLabel.text=@"未填写";
               // [cell.huiYuanBuDengButton setTitle:@"会员补登" forState:UIControlStateNormal];
            }
             [Global resizeForLable:cell.memberNameLabel WithText:cell.memberNameLabel.text parentView:self.view];
           // [self resizeLabel:cell.memberNameLabel];
            CGRect frame1=cell.memberNameLabel.frame;
            frame1.origin.x=cell.memberNameTagLabel.frame.origin.x+cell.memberNameTagLabel.frame.size.width+2;
            cell.memberNameLabel.frame=frame1;
            
            CGRect frame2=cell.dateTagLabel.frame;
            frame2.origin.x=cell.memberNameLabel.frame.origin.x+cell.memberNameLabel.frame.size.width+12;
            cell.dateTagLabel.frame=frame2;
            
            CGRect frame3=cell.dateLabel.frame;
            frame3.origin.x=cell.dateTagLabel.frame.origin.x+cell.dateTagLabel.frame.size.width+3;
            cell.dateLabel.frame=frame3;
        }
        
        NSString *statusStr=@"";
        if (orderStatusArray.count>0) {
            statusStr=[orderStatusArray objectAtIndex:indexPath.row];
           // NSLog(@"statusStr===%@",statusStr);
            cell.orderStatusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
            if ([statusStr isEqualToString:@"未收银"]) {
                [cell.orderStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                if (memberNameStr.length>0) {
                    cell.huiYuanBuDengButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                    
                    [cell.huiYuanBuDengButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                    
                    //[cell.confirmArrivalBtn setTintColor:];
                    [cell.huiYuanBuDengButton setUserInteractionEnabled:NO];
                }
                else
                {
                    cell.huiYuanBuDengButton.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                    [cell.huiYuanBuDengButton setUserInteractionEnabled:YES];
                    [cell.huiYuanBuDengButton setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];

                }
                [cell.buShouYinButton setUserInteractionEnabled:YES];
                cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                
                [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                
                          }
            else if ([statusStr isEqualToString:@"已取消"])
            {
                [cell.orderStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                
                [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                //[cell.confirmArrivalBtn setTintColor:];
                [cell.buShouYinButton setUserInteractionEnabled:NO];
                
                cell.huiYuanBuDengButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                
                [cell.huiYuanBuDengButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                
                //[cell.confirmArrivalBtn setTintColor:];
                [cell.huiYuanBuDengButton setUserInteractionEnabled:NO];
            }
            else if ([statusStr isEqualToString:@"已收定金"])
            {
                [cell.orderStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                [cell.buShouYinButton setUserInteractionEnabled:YES];
                [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                
                cell.huiYuanBuDengButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                
                [cell.huiYuanBuDengButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                
                //[cell.confirmArrivalBtn setTintColor:];
                [cell.huiYuanBuDengButton setUserInteractionEnabled:NO];
                
            }
            else if ([statusStr isEqualToString:@"已结算"])
            {
                [cell.orderStatusLabel setTextColor:[Global parseStatusColor:statusStr]];
                cell.buShouYinButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                
                [cell.buShouYinButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                //[cell.confirmArrivalBtn setTintColor:];
                [cell.buShouYinButton setUserInteractionEnabled:NO];
                
                //[cell.confirmArrivalBtn setTintColor:];
                if (memberNameStr.length>0) {
                [cell.huiYuanBuDengButton setUserInteractionEnabled:NO];
                cell.huiYuanBuDengButton.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                    
                [cell.huiYuanBuDengButton setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                }
                else
                {
                    cell.huiYuanBuDengButton.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                    [cell.huiYuanBuDengButton setUserInteractionEnabled:YES];
                    [cell.huiYuanBuDengButton setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                }
            }
            
           // [self resizeLabel:cell.orderStatusLabel];
             [Global resizeForLable:cell.orderStatusLabel WithText:cell.orderStatusLabel.text parentView:self.view];
            
        }


        if (dateArray.count>0) {
            cell.dateLabel.text=[dateArray objectAtIndex:indexPath.row];
        }
        if (orderShipmentStatusArray.count>0) {
            NSString *str=@"";
            if ([[orderShipmentStatusArray objectAtIndex:indexPath.row]isEqualToString:@"N"]) {
                str=@"未发货";
            }
            if ([[orderShipmentStatusArray objectAtIndex:indexPath.row]isEqualToString:@"T"])
            {
                str=@"在途";
            }
            if ([[orderShipmentStatusArray objectAtIndex:indexPath.row]isEqualToString:@"A"])
            {
                str=@"已到货";
            }
            if ([[orderShipmentStatusArray objectAtIndex:indexPath.row]isEqualToString:@"Y"])
            {
                str=@"已发货";
            }

           // NSString *statusStr=[orderShipmentStatusArray objectAtIndex:indexPath.row];
            if (str.length>0) {
             cell.orderStatus1Label.text=[NSString stringWithFormat:@"【%@】",str];
            }
            else
            {
                cell.orderStatus1Label.text=@"";
            }
           
            if ([[orderShipmentStatusArray objectAtIndex:indexPath.row]isEqualToString:@"N"]) {
                [cell.orderStatus1Label setTextColor:[Global parseStatusColor:statusStr]];
            }
            else if ([[orderShipmentStatusArray objectAtIndex:indexPath.row]isEqualToString:@"T"]) {
                [cell.orderStatus1Label setTextColor:[Global parseStatusColor:statusStr]];
            }
            else if ([[orderShipmentStatusArray objectAtIndex:indexPath.row]isEqualToString:@"A"]) {
                [cell.orderStatus1Label setTextColor:[Global parseStatusColor:statusStr]];
            }
            
            else if ([[orderShipmentStatusArray objectAtIndex:indexPath.row]isEqualToString:@"Y"]) {
                [cell.orderStatus1Label setTextColor:[Global parseStatusColor:statusStr]];
            }
            CGRect frame =cell.orderStatus1Label.frame;
            frame.origin.x=cell.orderStatusLabel.frame.origin.x+cell.orderStatusLabel.frame.size.width-3;
            cell.orderStatus1Label.frame=frame;

        }
        NSString *numberStr=@"";
        NSString *weightStr=@"";
        NSString *nameStr=@"";
        if (orderTotalNumberArray.count>0) {
            numberStr=[NSString stringWithFormat:@"%ld",(long)[[orderTotalNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (orderWeightArray.count>0) {
             weightStr=[NSString stringWithFormat:@"%0.02f",[[orderWeightArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (productNameArray.count>0) {
            nameStr=[productNameArray objectAtIndex:indexPath.row];
            if ([numberStr floatValue]>1) {
                 cell.productNameLabel.text=[NSString stringWithFormat:@"%@...  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            else
            {
            cell.productNameLabel.text=[NSString stringWithFormat:@"%@  共%@件/%@g",nameStr,numberStr,weightStr];
            }
            [Global resizeForLable:cell.productNameLabel WithText:cell.productNameLabel.text parentView:self.view];
           // [self resizeLabel:cell.productNameLabel];
            CGRect frame=cell.priceTagLabel.frame;
            frame.origin.x=cell.productNameLabel.frame.origin.x+cell.productNameLabel.frame.size.width+16;
            cell.priceTagLabel.frame=frame;
            
            CGRect frame1=cell.priceLabel.frame;
            frame1.origin.x=cell.priceTagLabel.frame.origin.x+cell.priceTagLabel.frame.size.width+3;
            cell.priceLabel.frame=frame1;

        }
        if (priceArray.count>0) {
            float AvgPrice=[[priceArray objectAtIndex:indexPath.row] floatValue];
            NSString *AvgPriceStr=[Global floatConvertPercentile:AvgPrice];
            cell.priceLabel.text=[NSString stringWithFormat:@"¥%@",AvgPriceStr];
        }
        if (indexPath.row == [orderNumArray count] - 1)
        {
            if (_PageIndex<=_TotalPage) {
                //  NSLog(@"###LOADING???");
                [self loadOrderNextPage:_PageIndex];
            }
        }
        return cell;
    }
        else  if (tableView==_searchMemberTableView) {
        
        
        static NSString * const  MemberListIdentifier = @"MemberListCellIdentifier";
        SearchMemberTableViewCell *cell=( SearchMemberTableViewCell *)[tableView dequeueReusableCellWithIdentifier: MemberListIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"SearchMemberTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
        if (memberSexArray.count>0) {
            if ([[memberSexArray objectAtIndex:indexPath.row] isEqualToString:@"男"]) {
                [cell.sexImageView setImage:[UIImage imageNamed:@"nan_.png"]];
            }
            else
                [cell.sexImageView setImage:[UIImage imageNamed:@"nv_.png"]];
        }
        
        if (memberGradeArray.count>0) {
            cell.gradeLabel.text=[memberGradeArray objectAtIndex:indexPath.row];
            //[self resizeLabel:cell.gradeLabel];
            [Global resizeForLable:cell.gradeLabel WithText:cell.gradeLabel.text parentView:_searchMemberViewContainer];
        }

        if (memberPhoneArray.count>0&&memberNameArray.count>0) {
            NSString *phoneStr=[memberPhoneArray objectAtIndex:indexPath.row];
            NSString *nameStr=[memberNameArray objectAtIndex:indexPath.row];
            NSString *str1=@"(";
            NSString *str2=@")";
            cell.nameAndPhoneLabel.text=[NSString stringWithFormat:@"%@%@%@%@",nameStr,str1,phoneStr,str2];
          //  [self resizeLabel:cell.nameAndPhoneLabel];
             [Global resizeForLable:cell.nameAndPhoneLabel WithText:cell.nameAndPhoneLabel.text parentView:_searchMemberViewContainer];
            
            CGRect frame=cell.sexImageView.frame;
            frame.origin.x=cell.nameAndPhoneLabel.frame.origin.x+cell.nameAndPhoneLabel.frame.size.width;
            cell.sexImageView.frame=frame;
            
            CGRect frame1=cell.gradeTagLabel.frame;
            frame1.origin.x=cell.sexImageView.frame.origin.x+cell.sexImageView.frame.size.width+11;
            cell.gradeTagLabel.frame=frame1;
            
            CGRect frame2=cell.gradeLabel.frame;
            frame2.origin.x=cell.gradeTagLabel.frame.origin.x+cell.gradeTagLabel.frame.size.width+2;
            cell.gradeLabel.frame=frame2;
            
            CGRect frame3=cell.integralTagLabel.frame;
            frame3.origin.x=cell.gradeLabel.frame.origin.x+cell.gradeLabel.frame.size.width+11;
            cell.integralTagLabel.frame=frame3;
            
            CGRect frame4=cell.integralLabel.frame;
            frame4.origin.x=cell.integralTagLabel.frame.origin.x+cell.integralTagLabel.frame.size.width+2;
            cell.integralLabel.frame=frame4;
        }
        if (memberAddressArray.count>0) {
            NSString *addressStr1=[memberAddressArray objectAtIndex:indexPath.row];
            if (addressStr1.length>0) {
                cell.addressLabel.text=addressStr1;
            }
            else
            {
                cell.addressLabel.text=@"未填写";
            }
        }
        if (memberIntegralArray.count>0) {
            cell.integralLabel.text=[NSString stringWithFormat:@"%ld",(long)[[memberIntegralArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (indexPath.row == [memberCodeArray count] - 1)
        {
            if (_memberPageIndex<=_memberTotalPage) {
                //  NSLog(@"###LOADING???");
                [self loadMemberNextPage:_memberPageIndex];
            }
        }
        return cell;
    }

    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
  if (tableView==_orderListTabelView)
{
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
    orderDetailVC=[[OrderDetailViewController alloc] init];
    orderDetailVC.delegate=self;
    orderDetailVC.docNumStr=[orderNumArray objectAtIndex:indexPath.row];
       
    orderDetailVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:orderDetailVC];
    [self.view addSubview:orderDetailVC.view];
    
    orderListCellTag=indexPath.row;
  
}
else if (tableView==_searchMemberTableView)
{
   // NSLog(@"buShouYinOrBuDengStr====%@",buShouYinOrBuDengStr);
   // if ([buShouYinOrBuDengStr isEqualToString:@"BUSHOUYIN"]) {
    CGRect frame0=_searchMemberViewContainer.frame;
    frame0.origin.y=768;
    [_searchMemberViewContainer setFrame:frame0];

    memberCodeStr=[memberCodeArray objectAtIndex:indexPath.row];
    
   // [self resizeLabel:_memberAndPhoneLabel];
        
    integralAvailabalStr=[NSString stringWithFormat:@"%0.02f",[[memberIntegralAmountArray objectAtIndex:indexPath.row] floatValue]];
   

       //
//     if ([buShouYinOrBuDengStr isEqualToString:@"BUDENG"])
//      {
         //NSLog(@"eeeeeee");
        memberCodeStr=[memberCodeArray objectAtIndex:indexPath.row];
        [self submitTheSelectedMember];
      // }
    //}
 }
}
//

//orderDetailDelegate
-(void)productItemDetail:(NSString *)codeString
{
    _isLoad=@"Y";
    if (commonProductDetailVC.view!=nil) {
        
        [commonProductDetailVC removeFromParentViewController];
        [commonProductDetailVC.view removeFromSuperview];
        
    }
    commonProductDetailVC=[[CommonProductDetailViewController alloc] init];
    commonProductDetailVC.delegate=self;
    commonProductDetailVC.codeStr=codeString;
    commonProductDetailVC.view.frame = CGRectMake(0,
                                            0,
                                            self.view.bounds.size.width,
                                            self.view.bounds.size.height);
    
    [self addChildViewController:commonProductDetailVC];
    [self.view addSubview:commonProductDetailVC.view];
}
-(void)commonProductDetailShopCartClick
{
    if ([self.delegate respondsToSelector:@selector(OrderShopCtarClick)]) {
        
        [self.delegate OrderShopCtarClick];
    }
    
}
-(void)orderDetailAlphaViewClick
{
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
}
-(void)RelateDepositBtnClick
{
    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }
    depositDetailVC=[[DepositDetailViewController alloc] init];
    depositDetailVC.delegate=self;
    depositDetailVC.docNumStr=orderDetailVC.relatedDocNumLabel.text;
    depositDetailVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:depositDetailVC];
    [self.view addSubview:depositDetailVC.view];

}
-(void)CancelOrderBtnClick
{
    //    if (orderDetailVC.view!=nil) {
    //      //  NSLog(@"rrwrwrwrwrw");
    //        [orderDetailVC removeFromParentViewController];
    //        [orderDetailVC.view removeFromSuperview];
    //
    //    }
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }
    cancelOrderVC=[[CancelOrderOrDepositViewController alloc] init];
    cancelOrderVC.delegate=self;
    cancelOrderVC.DocNumStr=orderDetailVC.detailNumLabel.text;
    cancelOrderVC.DocTypeStr=@"Order";
    cancelOrderVC.titleStr=@"取消订单";

    cancelOrderVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:cancelOrderVC];
    [self.view addSubview:cancelOrderVC.view];
   // [self.view bringSubviewToFront:cancelOrderVC.view];
    
}
//DepositDetailDelegate
-(void)DepositDetailAlphaViewClick
{
    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }

}
-(void)DepositDetailCanCelDepositClick
{
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }
    cancelOrderVC=[[CancelOrderOrDepositViewController alloc] init];
    cancelOrderVC.delegate=self;
    cancelOrderVC.DocNumStr=depositDetailVC.detailNumLabel.text;
    cancelOrderVC.DocTypeStr=@"Deposit";
    cancelOrderVC.titleStr=@"取消定金单";
    cancelOrderVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:cancelOrderVC];
    [self.view addSubview:cancelOrderVC.view];

}
-(void)DepositDetailRelateOrderClick
{
    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
    orderDetailVC=[[OrderDetailViewController alloc] init];
    orderDetailVC.delegate=self;
    orderDetailVC.docNumStr=[orderNumArray objectAtIndex:orderListCellTag];
    orderDetailVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:orderDetailVC];
    [self.view addSubview:orderDetailVC.view];
    
    


}
//cancelOrderOrDepositDelegate
-(void)CancelOrderAlphaViewClick
{
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }
    
    
}
-(void)confirmCancelOrderOrDepositBtnClick
{
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }

    [orderNumArray removeAllObjects];
    [orderTotalNumberArray removeAllObjects];
    [orderStatusArray removeAllObjects];
    [orderDocTypeArray removeAllObjects];
    [orderWeightArray removeAllObjects];
    [orderShipmentStatusArray removeAllObjects];
    [productNameArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [memberNameListArray removeAllObjects];
    [priceArray removeAllObjects];
    [dateArray removeAllObjects];
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];
    
}

-(void)submitTheSelectedMember
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
         [params setObject:memberCodeStr forKey:@"MemberCode"];
        [params setObject:orderStr forKey:@"DocNum"];
        [params setObject:@"DOrder" forKey:@"DocType"];
        
        // NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"Guide/AddMemberTobills" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
          //  NSLog(@"severdata======%@",severDataDict.dataDict);
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    CGRect frame1=_searchMemberViewContainer.frame;
                    frame1.origin.y=768;
                    [_searchMemberViewContainer setFrame:frame1];
                    [orderNumArray removeAllObjects];
                    [orderTotalNumberArray removeAllObjects];
                    [orderStatusArray removeAllObjects];
                    [orderStatus1Array removeAllObjects];
                    [orderDocTypeArray removeAllObjects];
                    [orderWeightArray removeAllObjects];
                    [orderShipmentStatusArray removeAllObjects];
                    [productNameArray removeAllObjects];
                    [guideNameArray removeAllObjects];
                    [memberNameListArray removeAllObjects];
                    [priceArray removeAllObjects];
                    [dateArray removeAllObjects];
                    
                    
                    _PageIndex=0;
                    [self loadOrderNextPage:_PageIndex];

                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        if (_timer!=nil) {
                            [_timer invalidate];
                            _timer=nil;
                        }
                       [Global loginViewController:self noteStr:requestResultStr];
                     //   [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }

}
-(void)CashierSuccess
{
    if (cashierVC.view!=nil) {
        
        [cashierVC removeFromParentViewController];
        [cashierVC.view removeFromSuperview];
        
    }
    [orderNumArray removeAllObjects];
    [orderTotalNumberArray removeAllObjects];
    [orderStatusArray removeAllObjects];
    [orderWeightArray removeAllObjects];
    [orderShipmentStatusArray removeAllObjects];
    [productNameArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [memberNameListArray removeAllObjects];
    [priceArray removeAllObjects];
    [dateArray removeAllObjects];
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];
    
    
}

//
-(void)buShouYinBtnClick:(NSUInteger)tag
{
    [_searchTextField resignFirstResponder];
    cellTag=tag;
    if (cashierVC.view!=nil) {
        
        [cashierVC removeFromParentViewController];
        [cashierVC.view removeFromSuperview];
        
    }
    cashierVC=[[CashierViewController alloc] init];
    cashierVC.delegate=self;
    cashierVC.docTypeStr=@"Order";
    cashierVC.docNumStr=[orderNumArray objectAtIndex:tag];
    cashierVC.view.frame = CGRectMake(0,
                                      0,
                                      self.view.bounds.size.width,
                                      self.view.bounds.size.height);
    
    [self addChildViewController:cashierVC];
    [self.view addSubview:cashierVC.view];
    [self.view bringSubviewToFront:cashierVC.view];

}

-(void)huiYuanBuDengBtnClick:(NSUInteger)tag;
{
   
    [_searchTextField resignFirstResponder];
    cellTag=tag;

   // addMemberGuideCodeStr=[Global getGuideCodeStr];
    
    
    buShouYinOrBuDengStr=@"BUDENG";
   
    orderStr=[orderNumArray objectAtIndex:tag];
    if (addMemberVC.view!=nil) {
        
        [addMemberVC removeFromParentViewController];
        [addMemberVC.view removeFromSuperview];
        
    }
    addMemberVC=[[AddMemberViewController alloc] init];
    addMemberVC.delegate=self;
    addMemberVC.addOrEditStr=@"A";
    addMemberVC.userCodeStr=@"";
    addMemberVC.docNumStr=orderStr;
    addMemberVC.view.frame = CGRectMake(0,
                                        0,
                                        self.view.bounds.size.width,
                                        self.view.bounds.size.height);
    
    [self addChildViewController:addMemberVC];
    [self.view addSubview:addMemberVC.view];
}
- (void)textClick
{
    [_searchMemberTextField becomeFirstResponder];
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField==_searchMemberTextField) {
        [_searchMemberTextField resignFirstResponder];
        [memberCodeArray removeAllObjects];
        [memberNameArray removeAllObjects];
        [memberPhoneArray removeAllObjects];
        [memberGradeArray removeAllObjects];
        [memberAddressArray removeAllObjects];
        [memberIntegralArray removeAllObjects];
        [memberIntegralAmountArray removeAllObjects ];
        [memberSexArray removeAllObjects];
        
        _memberPageIndex=0;
        [self loadMemberNextPage:_memberPageIndex];
        
        
        // return NO;
    }
       if (textField==_searchTextField) {
        [orderNumArray removeAllObjects];
        [orderTotalNumberArray removeAllObjects];
        [orderStatusArray removeAllObjects];
        [orderWeightArray removeAllObjects];
        [orderShipmentStatusArray removeAllObjects];
        [productNameArray removeAllObjects];
        [guideNameArray removeAllObjects];
        [memberNameListArray removeAllObjects];
        [priceArray removeAllObjects];
        [dateArray removeAllObjects];

        _PageIndex=0;
        [self loadOrderNextPage:_PageIndex];
        [_searchTextField resignFirstResponder];
    }
    

       return YES;
}

-(void)addOrEditMemberSuccess:(NSString *)memberCodeString memberGradeString:(NSString *)memberGradeString memberNameString:(NSString *)memberNameString memberPhoneString:(NSString *)memberPhoneString memberSexString:(NSString *)memberSexString memberIntegralString:(NSString *)memberIntegralString
{
   
//    if ([buShouYinOrBuDengStr  isEqualToString:@"BUSHOUYIN"]) {
    
        memberCodeStr=memberCodeString;
        
        integralAvailabalStr=@"";
  //  }
    

    [orderNumArray removeAllObjects];
    [orderTotalNumberArray removeAllObjects];
    [orderStatusArray removeAllObjects];
    [orderStatus1Array removeAllObjects];
    [orderDocTypeArray removeAllObjects];
    [orderWeightArray removeAllObjects];
    [orderShipmentStatusArray removeAllObjects];
    [productNameArray removeAllObjects];
    [guideNameArray removeAllObjects];
    [memberNameListArray removeAllObjects];
    [priceArray removeAllObjects];
    [dateArray removeAllObjects];
    
    
    _PageIndex=0;
    [self loadOrderNextPage:_PageIndex];

}
-(void)commonSelectMemberBtnClick
{
    if (addMemberVC.view!=nil) {
        if (addMemberVC.timer!=nil) {
            [addMemberVC.timer invalidate];
            addMemberVC.timer=nil;
        }
        
        [addMemberVC removeFromParentViewController];
        [addMemberVC.view removeFromSuperview];
        
    }

    _totalMemberLabel.text= @"共有0个结果";
    _searchMemberTextField.text=@"";
    [_searchMemberTextField resignFirstResponder];
    [memberCodeArray removeAllObjects];
    [memberNameArray removeAllObjects];
    [memberPhoneArray removeAllObjects];
    [memberGradeArray removeAllObjects];
    [memberAddressArray removeAllObjects];
    [memberIntegralArray removeAllObjects];
    [memberIntegralAmountArray removeAllObjects];
    [memberSexArray removeAllObjects];
    [_searchMemberTableView reloadData];
    
    CGRect frame1=_searchMemberViewContainer.frame;
    frame1.origin.y=0;
    [_searchMemberViewContainer setFrame:frame1];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
